package org.gary.core.util;

import java.sql.Date;

import javax.annotation.Resource;

import org.gary.admin.service.LoggerService;

/**
 * 自动删除日志文件在每年的1，4，7，10月份的最后一个周日的凌晨6点1分自动执行一次
 * @author lengreen
 *
 */
public class AutoDeleteLoggerTask {
	private LoggerService loggerService;

	public void work() {
		try {
			Date now = new Date(System.currentTimeMillis());
			String[] dateArray = now.toString().split("-");
			String to = now.toString();
			int month = Integer.parseInt(dateArray[1]);
			String m = "";
			switch (month) {
				case 1 : m = "10"; break;
				case 4 : m = "01"; break;
				case 7 : m = "04"; break;
				case 10 : m = "07"; break;
			}
			String from = dateArray[0] + "-" + m + "-" + dateArray[2];
			loggerService.delete(from, to);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Resource
	public void setLoggerService(LoggerService loggerService) {
		this.loggerService = loggerService;
	}

	public LoggerService getLoggerService() {
		return loggerService;
	}
}
